package org.sardine.aop;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.sardine.util.ReflectionUtils;

public class AopUtils {
	
	public static Object invoke(Object target,Method method,Object[] args) throws Throwable{
		
		ReflectionUtils.makeAccessible(method);
		Object returnVal = null;
		
		try {
			
			returnVal = method.invoke(target, args);
			
		} catch (IllegalAccessException e) {
			throw new AopInvocationException("无法访问"+method+"方法",e);
		} catch (IllegalArgumentException e) {
			throw new AopInvocationException("可能参数错误，无法调用对象"+target+"的"+method+"方法",e);
		} catch (InvocationTargetException e) {
			throw e.getTargetException();
		}
		
		return returnVal;
	}

}
